package cn.thoughtworks.school.entities.vo;

import cn.thoughtworks.school.entities.Assignment;
import cn.thoughtworks.school.entities.Operation;
import cn.thoughtworks.school.entities.Task;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder;
import lombok.Data;

import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

@Data
@Builder
public class TaskHistoryVo {
    private Long id;
    private Long taskId;
    private Long topicId;
    private String title;
    private String content;
    private Boolean visible;
    private Long fromId;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date operateTime;
    private String username;
    private Operation operation;
    private List<Assignment> assignments;

    public static TaskHistoryVo build(Task task, String username) {
        return TaskHistoryVo.builder()
            .id(task.getId())
            .taskId(task.getTaskId())
            .topicId(task.getTopicId())
            .title(task.getTitle())
            .content(task.getContent())
            .visible(task.getVisible())
            .fromId(task.getFromId())
            .operateTime(task.getOperateTime())
            .username(username)
            .operation(task.getOperation())
            .assignments(task.getAssignments())
            .build();
    }
}
